package com.baimifan.renovation;

import android.app.Activity;
import android.graphics.Color;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.baimifan.renovation.adapter.DemoFragAdapter;
import com.baimifan.renovation.tools.statusBar;
import com.flyco.tablayout.SlidingTabLayout;
import com.gyf.barlibrary.ImmersionBar;

public class DemoActivity extends AppCompatActivity implements View.OnClickListener{
    private Float w, h, widthPixels, heightPixels;
    private LinearLayout flag;
    private Activity demo;
    private RelativeLayout demo_rl;
    private ImageView rl_iv;
    private SlidingTabLayout demo_tab;
    private ViewPager viewPager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo);
        demo = DemoActivity.this;
        ImmersionBar.with(demo).init();
        init();
        getDisplay();
        setLayoutParams();
        viewPager.setAdapter(new DemoFragAdapter(getSupportFragmentManager()));
        demo_tab.setViewPager(viewPager);
    }

    private void init () {
        flag = (LinearLayout) findViewById(R.id.demo_flag);
        demo_rl = (RelativeLayout) findViewById(R.id.demo_rl);
        rl_iv = (ImageView) findViewById(R.id.demo_rl_iv);
        demo_tab = (SlidingTabLayout) findViewById(R.id.demo_tab);
        viewPager = (ViewPager) findViewById(R.id.demo_viewpager);

        rl_iv.setOnClickListener(this);
    }

    private void setLayoutParams () {
        LinearLayout.LayoutParams params_flag = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                statusBar.getStatusBarHeight(demo));
        flag.setLayoutParams(params_flag);

        LinearLayout.LayoutParams params_rl = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                (int)(h*44));
        demo_rl.setLayoutParams(params_rl);

        RelativeLayout.LayoutParams params_iv = new RelativeLayout.LayoutParams((int)(w*8.5), (int)(h*16));
        params_iv.setMargins((int)(w*15), 0, 0, 0);
        params_iv.addRule(RelativeLayout.CENTER_VERTICAL);
        rl_iv.setLayoutParams(params_iv);

        LinearLayout.LayoutParams params_tab = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                (int)(h*49));
        demo_tab.setLayoutParams(params_tab);
        demo_tab.setBackgroundColor(Color.WHITE);
        demo_tab.setTextSelectColor(Color.parseColor("#FF5C34"));
        demo_tab.setTextUnselectColor(Color.parseColor("#141417"));
        demo_tab.setTextsize(15);
        demo_tab.setIndicatorHeight(4);
        demo_tab.setIndicatorWidth(24);
        demo_tab.setIndicatorColor(Color.parseColor("#FF5C34"));
        demo_tab.setTabSpaceEqual(true);
    }

    private void getDisplay() {
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        widthPixels = Float.valueOf(metrics.widthPixels);
        heightPixels = Float.valueOf(metrics.heightPixels);
        w = widthPixels / 360;
        h = heightPixels / 640;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.demo_rl_iv:
                finish();
                break;
        }
    }
}
